<template>
  <div class="box">
    
    <div class="card1">
      
      <div class="parent">
      <h3>订单管理</h3>
      <el-divider></el-divider>
      <el-form :inline="true" :model="orderForm" ref="orderForm" class="demo-form-inline" size="small">
        <el-form-item label="订单编号" prop="orderId">
          <el-input v-model="orderForm.orderId" placeholder="请输入订单编号"></el-input>
        </el-form-item>
        
        <el-form-item label="买家姓名" prop="accountName">
          <el-input v-model="orderForm.accountName" placeholder="请输入买家姓名"></el-input>
        </el-form-item>
        <el-form-item label="交易状态" prop="status">
          <el-select v-model="orderForm.status" placeholder="请选择交易状态" style="width: 190px;">
            <el-option label="已取消" value="0"></el-option>
            <el-option label="未支付" value="1"></el-option>
            <el-option label="已付款" value="2"></el-option>
            <el-option label="已接单" value="3"></el-option>
            <el-option label="已发货" value="4"></el-option>
            <el-option label="已收货" value="5"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="下单时间" prop="date">
          <el-date-picker
              v-model="orderForm.date"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="selectAllFlowerOrder">查询</el-button>
          <el-button type="info" @click="resetInfo">重置</el-button>
        </el-form-item>
      </el-form>
      <el-divider></el-divider>
      <!--订单表格-->
      <el-table
          :data="tableData"
          stripe
          border
          style="width: 100%">
        <el-table-column prop="newOrderId" label="订单编号" align="center" sortable></el-table-column>
        <el-table-column prop="accountName" label="买家姓名" align="center"></el-table-column>
<!--        <el-table-column prop="count" label="购买数量" align="center" sortable></el-table-column>-->
        <el-table-column prop="total" label="总金额(元)" align="center" sortable></el-table-column>
        <el-table-column prop="createTime" label="下单时间" align="center" sortable></el-table-column>
        <el-table-column prop="status" label="交易状态" align="center" sortable>
          <template slot-scope="{row}">
            <p v-if="row.status===0">已取消</p>
            <p v-if="row.status===1">未支付</p>
            <p v-if="row.status===2">已付款</p>
            <p v-if="row.status===3">已接单</p>
            <p v-if="row.status===4">已发货</p>
            <p v-if="row.status===5">已收货</p>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button @click="toOrderItem(scope.row)" type="text" size="small">查看详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-divider></el-divider>
      <!--分页插件-->
      
        <el-pagination align="center"  style="margin-top:30px; "
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="pageNum"
            :page-sizes="[3, 5, 10, 15]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
        </el-pagination>
      
    </div>
      <router-view/>
    </div>
  </div>
</template>

<script>


export default {
  name: "OrderView",
  // 数据
  data() {
    return {
      pageNum:1,
      pageSize:5,
      total:10,
      
      orderForm:{
        orderId:null,
        accountName:null,
        status:null,
        date:[],
      },
      
      
      tableData: [],
    }
  },
  // 方法
  methods: {
    handleSizeChange(val) {
      this.pageSize =val;
      this.selectAllFlowerOrder();
    },
    handleCurrentChange(val) {
     this.pageNum =val;
      this.selectAllFlowerOrder();
    },

    toOrderItem(row){
      this.$router.push({path:'/orderitem',query:{orderId:row.newOrderId}});
    },
    
    selectAllFlowerOrder(){
      // 获取所有订单
      this.$axios.get("/flowerorder/selectFlowerOrderByMerchant",{
        params:{
          pageNum:this.pageNum,
          pageSize:this.pageSize,
          orderId:this.orderForm.orderId,
          accountName:this.orderForm.accountName,
          status:this.orderForm.status,
          startTime:this.orderForm.date[0]?this.orderForm.date[0].getTime():null,
          endTime:this.orderForm.date[1]?this.orderForm.date[1].getTime():null,
        }
      }).then(response =>{
        console.log(response)
            if (response.data.code === 200){
              this.$message({
                type: "success",
                message: "订单管理查询成功",
              });
              this.tableData = response.data.data.list;
              this.pageNum = response.data.data.pageNum;
              this.pageSize = response.data.data.pageSize;
              this.total = response.data.data.total;
            }
          })
    },
    
    
    resetInfo(){
     this.$refs.orderForm.resetFields();
      this.selectAllFlowerOrder();
    },
  },
  
  mounted() {
    this.selectAllFlowerOrder(); // 查询所有订单
  }

}
</script>


<style scoped lang="less">
.box {
  border-radius: 4px;
  border: 1px solid white;
  background-color: white;
  margin: 30px 100px;
}

.box .card1 {
  margin: 20px 10px;
  text-align: left;
}
</style>